﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ENG.PSSAirbusSoundExtender
{
  public partial class FrmConsole : Form
  {
    public FrmConsole()
    {
      InitializeComponent();
    }

    private void FrmConsole_Load(object sender, EventArgs e)
    {
      Program.OverheadClick += new Program.ClickHandler(Program_OverheadClick);
      Program.CalibrationClick += new Program.ClickHandler(Program_CalibrationClick);
      Program.OverheadChange += new Program.OverheadChangeHandler(Program_OverheadChange);

      var s = PSS.GetSystems();

      foreach (var fItem in s)
      {
        fItem.IsOnChanged += new ASystem.IsOnChangedHandler(fItem_IsOnChanged);
        fItem.StatusChanged += new ASystem.StatusChangedHandler(fItem_StatusChanged);
      } // foreach (var fItem in s)
    }

    void Program_OverheadChange(bool isNowOverhead)
    {
      AddInfo("Program - IsNowOverhead: " + isNowOverhead.ToString());
    }

    void Program_CalibrationClick(Point point)
    {
      AddInfo("Program - calibration click: " + point.ToString());
    }

    void Program_OverheadClick(Point point)
    {
      AddInfo("Program - overhead click: " + point.ToString());
    }

    void fItem_StatusChanged(ASystem sender)
    {
      AddInfo("ASystem: " + sender.Name + " - Status: " + sender.Status.ToString());
    }

    void fItem_IsOnChanged(ASystem sender)
    {
      AddInfo("ASystem: " + sender.Name + " - IsOn: " + sender.IsOn);
    }

    private void AddInfo(string p)
    {
      txtInfo.Text += DateTime.Now.ToLongTimeString() +  " " + p + Environment.NewLine;
      txtInfo.SelectionStart = txtInfo.Text.Length;

      txtInfo.ScrollToCaret();
    }


  }
}
